﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Farigola.Engine.SystemData.Entity.Type
{
    /// <summary>
    /// Base class of class type: class, anonymClass,...
    /// </summary>
    public abstract class EntTypeClassBase : EntTypeDataBase
    {
        /// <summary>
        /// list of data members type.
        /// </summary>
        private List<EntTypeClassDataMember> _listEntTypeClassDataMember= new List<EntTypeClassDataMember>();

        //=====================================================================
        // Constructors.

        //---------------------------------------------------------------------
        /**
         * constructor.
         * 
         * @param systOrUser
         * @param id
         * @param name
         */
        public EntTypeClassBase(EntityDef.TypeSystOrUser systOrUser, EntityId id, String name)
            : base(systOrUser, id, name)
        {
        }

        //---------------------------------------------------------------------
        /**
         * constructor.
         * 
         * @param id
         * @param name
         */
        public EntTypeClassBase(EntityId id, String name)
            : base(id, name)
        {            
        }

        public List<EntTypeClassDataMember> listDataMember()
        {
            return _listEntTypeClassDataMember;
        }

        public int listDataMemberSize()
        {
            return _listEntTypeClassDataMember.Count;
        }


        //---------------------------------------------------------------------
        /**
         * Find the DM of the typeClass, by the name.
         * 
         * @param typeClass
         * @param nameDM
         * @return
         */
        public EntTypeClassDataMember FindDataMemberByName(String nameDM){
		// check the name, not null and not blank/empty
		if(nameDM==null)
			return null;
		nameDM= nameDM.Trim();
		if(nameDM.Length== 0)
			return null;
		
		// scan all data member
		foreach( EntTypeClassDataMember dm in _listEntTypeClassDataMember){
			if(dm.IsNameEquals(nameDM))
				// has same name, return it
				return dm;
		}
			
		// no Dm found with the provided name
		return null;
	}

        /**
         * Add a new data member, build by a factory (not here).
         * @param typeClassDM
         * @return
         */
        public bool addDataMember(EntTypeClassDataMember typeClassDM)
        {
            if (typeClassDM == null)
                return false;

            _listEntTypeClassDataMember.Add(typeClassDM);
            return true;
        }

    }
}
